package com.qkl.xiatang.app.workflow.utils;

import com.alibaba.fastjson.JSONObject;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

public class HttpUtil {

    public static String post(RestTemplate restTemplate, String url, Object body) {
        // 设置请求头
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        // 创建 HttpEntity 对象，用于包装请求体和请求头
        HttpEntity<String> requestEntity = new HttpEntity<>(JSONObject.toJSONString(body), headers);
        ResponseEntity<String> forEntity = restTemplate.postForEntity(url, requestEntity, String.class);
        return forEntity.getBody();
    }


}
